import React, { Component, Fragment } from "react"
import PropTypes from "prop-types"

export default class XiaoItem extends Component {
  constructor(props) {
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }
  // componentWillReceiveProps() {
  //   console.log("componentWillReceiveProps")
  // }
  // componentWillUnmount() {
  //   console.log("child - componentWillUnmount")
  // }
  shouldComponentUpdate(nextProps, nextState) {
    if (nextProps.content !== this.props.content) {
      return true
    } else {
      return false
    }
  }
  handleClick() {
    this.props.deleteItem(this.props.index)
  }
  render() {
    return (
      <Fragment>
        <li onClick={this.handleClick}>
          {this.props.avname} 为你做-{this.props.content}
        </li>
      </Fragment>
    )
  }
}

XiaoItem.propTypes = {
  content: PropTypes.string,
  deleteItem: PropTypes.func,
  index: PropTypes.number,
  avname: PropTypes.string.isRequired
}
XiaoItem.defaultProps = {
  avname: "松岛枫"
}
